import threading
import paramiko

def ssh_command(ip, username, password, command):
    try:
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        client.connect(ip, username=username, password=password, timeout=5)

        # 执行命令
        for subcommand in command:
            stdin, stdout, stderr = client.exec_command(subcommand)
            print(f"Output from {ip}:")
            print(stdout.read().decode('utf-8'))

        client.close()
    except Exception as e:
        print(f"Error connecting to {ip}: {str(e)}")


def read_file(file_path):
    with open(file_path, 'r') as file:
        return file.read().splitlines()


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    shell_txt = read_file("E:\\shell.txt")
    ssh_command("192.168.1.1","root","P@ssw0rd",shell_txt)
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
